package gov.pbc.gx.nn.pz.impl;

import gov.pbc.gx.nn.pz.dao.XjpzDao;
import gov.pbc.gx.nn.pz.entity.Account;
import gov.pbc.gx.nn.pz.entity.HcXjpz;
import gov.pbc.gx.nn.pz.entity.HcpzXY;
import gov.pbc.gx.nn.pz.entity.PzFont;

import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileOutputStream;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import javax.annotation.Resource;
import javax.imageio.ImageIO;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.bstek.bdf2.core.business.IUser;
import com.bstek.bdf2.core.context.ContextHolder;
import com.bstek.bdf2.core.exception.NoneLoginException;
import com.bstek.dorado.annotation.DataProvider;
import com.bstek.dorado.annotation.DataResolver;
import com.bstek.dorado.annotation.Expose;
import com.bstek.dorado.data.variant.Record;
import com.bstek.dorado.web.DoradoContext;

/**
 * 
 * @author jack.zhao 本类主要实现xjpz业务逻辑的操作
 * 
 */

@Component("xjpzPR")
public class XjpzPR {
	private static final Integer PZ_CODE_ = 1;
	private static final Integer Font_Size = 16;
	@Resource
	@Autowired
	private XjpzDao xjpzDao;

	@Transactional
	@DataProvider
	public Record getXjpzs() {
		try {
			IUser loginuser = ContextHolder.getLoginUser();
			if (loginuser == null)
				return null;
			if (loginuser.getDepts() == null || loginuser.getDepts().size() <= 0)
				return null;
			Record record = new Record();
			record.put("pzdate", new Date());
			ArrayList<HcXjpz> lists = (ArrayList<HcXjpz>) xjpzDao.getMuByDeptName();
			if (lists.isEmpty()) {
				HcXjpz e = new HcXjpz();
				// e.setDeptId(xjpzDao.getDeptId());
				e.setPzDate(new Date());
				e.setPzTemplate("新建模板");
				e.setIsSign(1);
				lists.add(e);
				record.put("xjpz", lists);
			} else {
				lists.get(0).setPzDate(new Date());
				record.put("xjpz", lists);
			}
			// List<Record> pys = new ArrayList<Record>();
			// Map<String, Record> pym = new HashMap<String, Record>();
			// Record recordpy = new Record();

			List<HcpzXY> xjpzXYs = xjpzDao.getHcPzXYs(PZ_CODE_);
			if (xjpzXYs != null && !xjpzXYs.isEmpty()) {
				record.put("pys", xjpzXYs);
			} else {

				xjpzXYs = new ArrayList<HcpzXY>();
				HcpzXY xjpzXY = new HcpzXY();
				xjpzXY.setProperty("页边距", 50, 50, Font_Size);
				xjpzXYs.add(xjpzXY);

				xjpzXY = new HcpzXY();
				xjpzXY.setId(UUID.randomUUID().toString());
				xjpzXY.setProperty("年", 255, 65, Font_Size);
				xjpzXYs.add(xjpzXY);

				xjpzXY = new HcpzXY();
				xjpzXY.setProperty("月", 325, 65, Font_Size);
				xjpzXYs.add(xjpzXY);

				xjpzXY = new HcpzXY();
				xjpzXY.setProperty("日", 385, 65, Font_Size);
				xjpzXYs.add(xjpzXY);

				// xjpzXY = new HcpzXY();
				// xjpzXY.setProperty("流水号", 545, 65);
				// xjpzXYs.add(xjpzXY);

				xjpzXY = new HcpzXY();
				xjpzXY.setProperty("交款单位名称", 155, 105, Font_Size);
				xjpzXYs.add(xjpzXY);

				xjpzXY = new HcpzXY();
				xjpzXY.setProperty("交款单位帐号", 155, 155, Font_Size);
				xjpzXYs.add(xjpzXY);

				xjpzXY = new HcpzXY();
				xjpzXY.setProperty("附件数量", 695, 255, Font_Size);
				xjpzXYs.add(xjpzXY);

				xjpzXY = new HcpzXY();
				xjpzXY.setProperty("摘要", 60, 265, Font_Size);
				xjpzXYs.add(xjpzXY);

				xjpzXY = new HcpzXY();
				xjpzXY.setProperty("小写金额", 679, 222, Font_Size);
				xjpzXYs.add(xjpzXY);

				xjpzXY = new HcpzXY();
				xjpzXY.setProperty("大写金额", 130, 200, Font_Size);
				xjpzXYs.add(xjpzXY);

			}

			record.put("pys", xjpzXYs);
			return record;
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			return null;
		}
	}

	// var param = {
	// zzpz : view.get("#dataSetxjpz.data.zzpz.current"),
	// pzdate : view.get("#dataSetxjpz.data.pzdate"),
	// pym : view.get("#dataSetxjpz.data.pym"),
	// fontzh : view.get("#dataSetxjpz.data.fontzh"),
	// fonten : view.get("#dataSetxjpz.data.fonten")
	// }

	@SuppressWarnings("unchecked")
	private void setImageData(Graphics2D graphics, Map<String, Object> param) {
		try {
			HcXjpz hcXjpz = (HcXjpz) param.get("xjpz");

			Date pzdate = (Date) param.get("pzdate");
			int pyx = (int) Integer.parseInt(param.get("x").toString());
			int pyy = (int) Integer.parseInt(param.get("y").toString());
			String fontzh = param.get("fontzh").toString();
			String fonten = param.get("fonten").toString();
			// int pyx = -31, pyy = -27;
			// x = 0;
			// y = 0;
			// Map<String, Object> pym = (Map<String, Object>) param.get("pym");
			graphics.setBackground(Color.WHITE);
			graphics.setColor(Color.BLACK);
			// Font zhFont = new Font(fontzh, Font.PLAIN, 16);
			// Font enFont = new Font(fonten, Font.PLAIN, 16);
			List<HcpzXY> hcpzxys = (List<HcpzXY>) param.get("pys");
			for (HcpzXY pym : hcpzxys) {
				int fontSize = pym.getFontSize();
				Font zhFont = new Font(fontzh, Font.PLAIN, fontSize);
				Font enFont = new Font(fonten, Font.PLAIN, fontSize);
				graphics.setFont(enFont);
				int x = pym.getX() + pyx;
				int y = pym.getY() + pyy;
				String lable = pym.getLabel();
				// System.out.println(lable);
				if (pzdate != null) {
					Calendar calendar = Calendar.getInstance();
					calendar.setTime(pzdate);
					if (lable.equals("年")) {
						graphics.drawString(String.format("%04d", calendar.get(Calendar.YEAR)), x, y);
					}
					if (lable.equals("月")) {
						graphics.drawString(String.format("%02d", calendar.get(Calendar.MONTH) + 1), x, y);

					}
					if (lable.equals("日")) {
						graphics.drawString(String.format("%02d", calendar.get(Calendar.DATE)), x, y);
					}

				}
				if (hcXjpz != null) {
					// if (lable.equals("流水号")) {
					// if (hcXjpz.getSerialnumber() != null) {
					// graphics.setFont(enFont);
					// graphics.drawString(hcXjpz.getSerialnumber(), x, y);
					// }
					// }
					if (lable.equals("交款单位名称")) {
						if (hcXjpz.getCompanyName() != null) {
							graphics.setFont(zhFont);
							graphics.drawString(hcXjpz.getCompanyName(), x, y);
						}
					}
					if (lable.equals("交款单位帐号")) {
						if (hcXjpz.getCompanyAccount() != null) {
							graphics.setFont(zhFont);
							graphics.drawString(hcXjpz.getCompanyAccount(), x, y);
						}
					}
					if (lable.equals("附件数量")) {
						graphics.setFont(enFont);
						if (hcXjpz.getAttachmentCount() != null) {
							graphics.drawString(String.valueOf(hcXjpz.getAttachmentCount()), x, y);
						}

					}
					if (lable.equals("摘要")) {
						if (hcXjpz.getRemark() != null) {
							graphics.setFont(zhFont);
							String[] strs = hcXjpz.getRemark().split("\n");
							for (int i = 0; i < strs.length; i++) {
								graphics.drawString(strs[i], x, y + i * zhFont.getSize());
							}
							// for (String line :
							// hcXjpz.getRemark().split("\n")){
							// graphics.drawString(line, x, y +=
							// graphics.getFontMetrics().getHeight());
							// }
						}
					}

					// if (hcXjpz.getRemark() != null) {
					// graphics.setFont(zhFont);
					// pyx = Integer.parseInt(((Map<String, Object>) pym
					// .get("remark")).get("x").toString());
					// pyy = Integer.parseInt(((Map<String, Object>) pym
					// .get("remark")).get("y").toString());
					//
					// String[] strs = hcXjpz.getRemark().split("\n");
					// for (int i = 0; i < strs.length; i++) {
					// graphics.drawString(strs[i], 32 + x + pyx, 270 + i
					// * 20 + y + pyy);
					// }
					// }
					if (lable.equals("小写金额")) {
						graphics.setFont(enFont);
						DecimalFormat df = new DecimalFormat(".00");
						char[] chars;
						// if (hcXjpz.getIsSign()) {
						// chars = ("¥" +
						// df.format(hcXjpz.getAmountNum()).replace(".",
						// "")).toCharArray();
						// } else {
						// chars = df.format(hcXjpz.getAmountNum())
						// .replace(".", "").toCharArray();
						// }
						int endX = x;
						// for (int i = 0; i < chars.length; i++) {
						// graphics.drawString(chars[chars.length - i - 1] + "",
						// endX - i * 15 - i / 5, y);
						// }
						if (hcXjpz.getAmountNum() != null) {
							if (hcXjpz.getIsSign() == 0) {
								chars = (df.format(hcXjpz.getAmountNum()).replace(".", "")).toCharArray();
								for (int i = 0; i < chars.length; i++) {
									graphics.drawString(chars[chars.length - i - 1] + "", endX - i * 15 - i / 5, y);
								}
							}
							if (hcXjpz.getIsSign() == 1) {
								chars = ("¥" + df.format(hcXjpz.getAmountNum()).replace(".", "")).toCharArray();
								for (int i = 0; i < chars.length; i++) {
									graphics.drawString(chars[chars.length - i - 1] + "", endX - i * 15 - i / 5, y);
								}
							}
							if (hcXjpz.getIsSign() == 2) {
								chars = ("HKD" + df.format(hcXjpz.getAmountNum()).replace(".", "")).toCharArray();
								for (int i = 0; i < chars.length; i++) {
									graphics.drawString(chars[chars.length - i - 1] + "", endX - i * 15 - i / 5, y);
								}
							}
							if (hcXjpz.getIsSign() == 3) {
								chars = ("USD" + df.format(hcXjpz.getAmountNum()).replace(".", "")).toCharArray();
								for (int i = 0; i < chars.length; i++) {
									graphics.drawString(chars[chars.length - i - 1] + "", endX - i * 15 - i / 5, y);
								}
							}
							if (hcXjpz.getIsSign() == 4) {
								chars = (df.format(hcXjpz.getAmountNum()).replace(".", "")).toCharArray();
								for (int i = 0; i < chars.length; i++) {
									graphics.drawString(chars[chars.length - i - 1] + "", endX - i * 15 - i / 5, y);
								}
							}
						}

					}
					if (lable.equals("大写金额")) {
						graphics.setFont(zhFont);
						int rowcount = 20;
						if (hcXjpz.getAmountNum() != null) {
							if (hcXjpz.getAmountZh() != null) {
								if (hcXjpz.getIsSign() == 0) {
									if (hcXjpz.getAmountZh().length() > rowcount) {
										graphics.drawString(hcXjpz.getAmountZh().substring(0, rowcount), x, y);
										graphics.drawString(hcXjpz.getAmountZh().substring(rowcount), x, 20 + y);
									} else {
										graphics.drawString(hcXjpz.getAmountZh(), x, y);
									}
								}
								if (hcXjpz.getIsSign() == 1) {
									if (hcXjpz.getAmountZh().length() > rowcount) {
										graphics.drawString(hcXjpz.getAmountZh().substring(0, rowcount), x, y);
										graphics.drawString(hcXjpz.getAmountZh().substring(rowcount), x, 20 + y);
									} else {
										graphics.drawString(hcXjpz.getAmountZh(), x, y);
									}
								}
								if (hcXjpz.getIsSign() == 2) {
									if (hcXjpz.getAmountZh().length() > rowcount) {
										graphics.drawString("港币 " + hcXjpz.getAmountZh().substring(0, rowcount), x - 40, y);
										graphics.drawString(hcXjpz.getAmountZh().substring(rowcount), x, 20 + y);
									} else {
										graphics.drawString("港币 " + hcXjpz.getAmountZh(), x - 40, y - 3);
									}
								}
								if (hcXjpz.getIsSign() == 3) {
									if (hcXjpz.getAmountZh().length() > rowcount) {
										graphics.drawString("美元 " + hcXjpz.getAmountZh().substring(0, rowcount), x - 40, y);
										graphics.drawString(hcXjpz.getAmountZh().substring(rowcount), x, 20 + y);
									} else {
										graphics.drawString("美元 " + hcXjpz.getAmountZh(), x - 40, y - 3);
									}
								}

								if (hcXjpz.getIsSign() == 4) {
									if (hcXjpz.getAmountZh().length() > rowcount) {
										graphics.drawString(hcXjpz.getAmountZh().substring(0, rowcount), x, y);
										graphics.drawString(hcXjpz.getAmountZh().substring(rowcount), x, 20 + y);
									} else {
										graphics.drawString(hcXjpz.getAmountZh(), x, y);
									}
								}
							}
						}
					}
				}

			}

			// if (pzdate != null) {
			// graphics.setFont(enFont);
			// Calendar calendar = Calendar.getInstance();
			// calendar.setTime(pzdate);
			//
			// pyx = Integer.parseInt(((Map<String, Object>) pym.get("year"))
			// .get("x").toString());
			// pyy = Integer.parseInt(((Map<String, Object>) pym.get("year"))
			// .get("y").toString());
			//
			// graphics.drawString(
			// String.format("%04d", calendar.get(Calendar.YEAR)), 255
			// + x + pyx, 65 + y + pyy);
			//
			// pyx = Integer.parseInt(((Map<String, Object>) pym.get("month"))
			// .get("x").toString());
			// pyy = Integer.parseInt(((Map<String, Object>) pym.get("month"))
			// .get("y").toString());
			// graphics.drawString(
			// String.format("%02d", calendar.get(Calendar.MONTH) + 1),
			// 325 + x + pyx, 65 + y + pyy);
			// pyx = Integer.parseInt(((Map<String, Object>) pym.get("date"))
			// .get("x").toString());
			// pyy = Integer.parseInt(((Map<String, Object>) pym.get("date"))
			// .get("y").toString());
			// graphics.drawString(
			// String.format("%02d", calendar.get(Calendar.DATE)), 385
			// + x + pyx, 65 + y + pyy);
			// }
			// if (hcXjpz == null)
			// return;
			// if (hcXjpz.getSerialnumber() != null) {
			// graphics.setFont(enFont);
			// pyx = Integer.parseInt(((Map<String, Object>) pym
			// .get("serialnumber")).get("x").toString());
			// pyy = Integer.parseInt(((Map<String, Object>) pym
			// .get("serialnumber")).get("y").toString());
			// graphics.drawString(hcXjpz.getSerialnumber(), 545 + x + pyx, 65
			// + y + pyy);
			// }
			// if (hcXjpz.getCompanyname() != null) {
			// graphics.setFont(zhFont);
			// pyx = Integer.parseInt(((Map<String, Object>) pym
			// .get("companyname")).get("x").toString());
			// pyy = Integer.parseInt(((Map<String, Object>) pym
			// .get("companyname")).get("y").toString());
			// graphics.drawString(hcXjpz.getCompanyname(), 155 + x + pyx, 105
			// + y + pyy);
			// }
			// if (hcXjpz.getCompanyaccount() != null) {
			// graphics.setFont(enFont);
			// pyx = Integer.parseInt(((Map<String, Object>) pym
			// .get("companyaccount")).get("x").toString());
			// pyy = Integer.parseInt(((Map<String, Object>) pym
			// .get("companyaccount")).get("y").toString());
			// graphics.drawString(hcXjpz.getCompanyaccount(), 155 + x + pyx,
			// 155 + y + pyy);
			// }
			// if (hcXjpz.getAmountzh() != null) {
			// graphics.setFont(zhFont);
			// int rowcount = 20;
			// pyx = Integer.parseInt(((Map<String, Object>) pym
			// .get("amountzh")).get("x").toString());
			// pyy = Integer.parseInt(((Map<String, Object>) pym
			// .get("amountzh")).get("y").toString());
			// if (hcXjpz.getAmountzh().length() > rowcount) {
			// graphics.drawString(
			// hcXjpz.getAmountzh().substring(0, rowcount), 130
			// + x + pyx, 200 + y + pyy);
			// graphics.drawString(hcXjpz.getAmountzh()
			// .substring(rowcount), 130 + x + pyx, 220 + y + pyy);
			// } else
			// graphics.drawString(hcXjpz.getAmountzh(), 130 + x + pyx,
			// 210 + y + pyy);
			// }
			// if (hcXjpz.getAmountnum() > 0) {
			// graphics.setFont(enFont);
			// pyx = Integer.parseInt(((Map<String, Object>) pym
			// .get("amountnum")).get("x").toString());
			// pyy = Integer.parseInt(((Map<String, Object>) pym
			// .get("amountnum")).get("y").toString());
			// DecimalFormat df = new DecimalFormat(".00");
			// char[] chars;
			// if (hcXjpz.getIssign())
			// chars = ("¥" + df.format(hcXjpz.getAmountnum()).replace(
			// ".", "")).toCharArray();
			// else
			// chars = df.format(hcXjpz.getAmountnum()).replace(".", "")
			// .toCharArray();
			// int endX = 679 + pyx;
			// for (int i = 0; i < chars.length; i++) {
			// graphics.drawString(chars[chars.length - i - 1] + "", endX
			// - i * 15 - i / 5 + x, 222 + y + pyy);
			// }
			// }
			// if (hcXjpz.getRemark() != null) {
			// graphics.setFont(zhFont);
			// pyx = Integer
			// .parseInt(((Map<String, Object>) pym.get("remark"))
			// .get("x").toString());
			// pyy = Integer
			// .parseInt(((Map<String, Object>) pym.get("remark"))
			// .get("y").toString());
			//
			// String[] strs = hcXjpz.getRemark().split("\n");
			// for (int i = 0; i < strs.length; i++) {
			// graphics.drawString(strs[i], 32 + x + pyx, 270 + i * 20 + y
			// + pyy);
			// }
			// }
			// if (hcXjpz.getAttachmentcount() > 0) {
			// graphics.setFont(enFont);
			// pyx = Integer.parseInt(((Map<String, Object>) pym
			// .get("attachmentcount")).get("x").toString());
			// pyy = Integer.parseInt(((Map<String, Object>) pym
			// .get("attachmentcount")).get("y").toString());
			// graphics.drawString(hcXjpz.getAttachmentcount() + "", 695 + x
			// + pyx, 255 + y + pyy);
			// }
			// if (hcXjpz.getDirector() != null) {
			// graphics.setFont(zhFont);
			// pyx = Integer.parseInt(((Map<String, Object>) pym
			// .get("director")).get("x").toString());
			// pyy = Integer.parseInt(((Map<String, Object>) pym
			// .get("director")).get("y").toString());
			// graphics.drawString(hcXjpz.getDirector(), 60 + x + pyx, 407 + y
			// + pyy);
			// }
			// if (hcXjpz.getAcceptance() != null) {
			// graphics.setFont(zhFont);
			// pyx = Integer.parseInt(((Map<String, Object>) pym
			// .get("acceptance")).get("x").toString());
			// pyy = Integer.parseInt(((Map<String, Object>) pym
			// .get("acceptance")).get("y").toString());
			// graphics.drawString(hcXjpz.getAcceptance(), 225 + x + pyx, 407
			// + y + pyy);
			// }
			// if (hcXjpz.getTouching() != null) {
			// graphics.setFont(zhFont);
			// pyx = Integer.parseInt(((Map<String, Object>) pym
			// .get("touching")).get("x").toString());
			// pyy = Integer.parseInt(((Map<String, Object>) pym
			// .get("touching")).get("y").toString());
			// graphics.drawString(hcXjpz.getTouching(), 380 + x + pyx, 407
			// + y + pyy);
			// }
			// if (hcXjpz.getSupervise() != null) {
			// graphics.setFont(zhFont);
			// pyx = Integer.parseInt(((Map<String, Object>) pym
			// .get("supervise")).get("x").toString());
			// pyy = Integer.parseInt(((Map<String, Object>) pym
			// .get("supervise")).get("y").toString());
			// graphics.drawString(hcXjpz.getSupervise(), 550 + x + pyx, 407
			// + y + pyy);
			// }
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
	}

	@Expose
	public String getPrintImageAll(Map<String, Object> param) {
		try {
			if (param == null)
				return null;
			IUser loginuser = ContextHolder.getLoginUser();
			if (loginuser == null)
				throw new NoneLoginException("您未登录，请刷新页面后重试！！");
			param.put("x", 0);
			param.put("y", 0);
			BufferedImage imagepz = ImageIO.read(new File(DoradoContext.getCurrent().getServletContext().getRealPath("pz/xjpz.png")));
			Graphics2D graphicspz = (Graphics2D) imagepz.getGraphics();
			setImageData(graphicspz, param);
			// ByteArrayOutputStream bytestreampz=new ByteArrayOutputStream();
			String filename = "pz/temp/all_" + loginuser.getUsername() + ".png";
			FileOutputStream fo = new FileOutputStream(new File(DoradoContext.getCurrent().getServletContext().getRealPath(filename)));
			ImageIO.write(imagepz, "png", fo);
			fo.flush();
			fo.close();
			// String
			// str="data:image/png;base64,"+Base64.encodeBase64String(bytestreampz.toByteArray());
			// System.out.println(str.length()+","+bytestreampz.toByteArray().length);
			return filename;
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			return null;
		}
	}

	@Expose
	public String getPrintImageData(Map<String, Object> param) {
		try {
			if (param == null)
				return null;
			IUser loginuser = ContextHolder.getLoginUser();
			if (loginuser == null)
				throw new NoneLoginException("您未登录，请刷新页面后重试！！");
			param.put("x", -28);
			param.put("y", -33);
			BufferedImage imagedata = ImageIO.read(new File(DoradoContext.getCurrent().getServletContext().getRealPath("pz/xjpz.png")));
			// System.out.println(imagepz.getWidth()*1.0/96.0*24.5);
			// BufferedImage imagedata= new BufferedImage(imagepz.getWidth(),
			// imagepz.getHeight(), imagepz.getType());
			Graphics2D graphicsdata = (Graphics2D) imagedata.getGraphics();
			graphicsdata.setBackground(Color.WHITE);

			// 打印背景图片
			graphicsdata.clearRect(0, 0, imagedata.getWidth(), imagedata.getHeight());
			setImageData(graphicsdata, param);
			// ByteArrayOutputStream bytestreampz=new ByteArrayOutputStream();
			String filename = "pz/temp/data_" + loginuser.getUsername() + ".png";
			FileOutputStream fo = new FileOutputStream(new File(DoradoContext.getCurrent().getServletContext().getRealPath(filename)));
			ImageIO.write(imagedata, "png", fo);
			fo.flush();
			fo.close();
			// String
			// str="data:image/png;base64,"+Base64.encodeBase64String(bytestreampz.toByteArray());
			// System.out.println(str.length()+","+bytestreampz.toByteArray().length);
			return filename;
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			return null;
		}
	}

	@Expose
	public Map<String, Object> getUserInfo() {
		IUser loginuser = ContextHolder.getLoginUser();
		Map<String, Object> userinfo = new HashMap<String, Object>();
		if (loginuser == null) {
			userinfo.put("cname", "");
			userinfo.put("dept", "");
			return userinfo;
		}
		userinfo.put("cname", loginuser.getCname());
		if (loginuser.getDepts() == null || loginuser.getDepts().size() <= 0) {
			userinfo.put("dept", "");
			return userinfo;
		}
		userinfo.put("dept", loginuser.getDepts().get(0).getName());
		return userinfo;
	}

	@DataProvider
	public Collection<HcXjpz> getTypeByGroup() {
		ArrayList<HcXjpz> xjpzs = new ArrayList<HcXjpz>();
		xjpzs = (ArrayList<HcXjpz>) xjpzDao.getOneGroupByType();
		for (int i = 0; i < xjpzs.size(); i++) {
			xjpzs.get(i).setPzDate(new Date());
		}
		return xjpzs;

	}

	@SuppressWarnings("unused")
	@DataProvider
	public Collection<HcXjpz> getTepementNameByType(Map<String, Object> param) {
		if (param == null) {
			return null;
		}
		String type = (String) param.get("type");
		ArrayList<HcXjpz> xjpzs = new ArrayList<HcXjpz>();
		xjpzs = (ArrayList<HcXjpz>) xjpzDao.getCoByType(type);
		for (int i = 0; i < xjpzs.size(); i++) {
			xjpzs.get(i).setPzDate(new Date());
		}
		return xjpzs;
		// return xjpzDao.getCoByType(type);
	}

	@Expose
	public HcXjpz ajaxselectOneByTypeAndTemplate(Map<String, Object> param) {
		String type = (String) param.get("type");
		String pztemplate = (String) param.get("pzTemplate");
		if (type == null || pztemplate == null) {
			return null;
		}
		HcXjpz xjpz = xjpzDao.selectOneByTypeAndTemplate(type, pztemplate);
		xjpz.setPzDate(new Date());
		return xjpz;

	}

	@DataProvider
	public List<Record> getFonts() {
		return xjpzDao.getFonts();
	}

	@DataProvider
	public PzFont getFont() {
		return xjpzDao.getFont(PZ_CODE_);
	}

	@Transactional
	@DataResolver
	public void saveXjpz(HcXjpz hcXjpz) {
		xjpzDao.saveXjpz(hcXjpz);
	}

	@Transactional
	@DataResolver
	public void savepzXY(Collection<HcpzXY> hcpzxys) {
		xjpzDao.saveXjpzXY(hcpzxys);

	}

	@Transactional
	@DataResolver
	public void saveFont(PzFont pzFont) throws Exception {
		xjpzDao.updateFont(pzFont);
	}

	@Expose
	public void deleteTemplateById(String id) {
		if (StringUtils.isEmpty(id)) {
			return;
		}
		xjpzDao.deleteTemplateById(id);
	}

	@Expose
	public Account ajaxActionGetName(Map<String, Object> parameter) {
		String account = (String) parameter.get("account");
		return xjpzDao.getAccountName(account);

	}

	@Expose
	public boolean updateTempalteName(Map<String, Object> parameter) {
		String id = (String) parameter.get("id");
		String pzTemplate = (String) parameter.get("pzTemplate");
		return xjpzDao.updateTemplateNameDao(pzTemplate, id);
	}

	@Expose
	public boolean updateTempalteType(Map<String, Object> parameter) {
		String id = (String) parameter.get("id");
		String type = (String) parameter.get("type");
		return xjpzDao.updateTemplateTypeDao(type, id);
	}
}
